const { ipcRenderer   } = require('electron')

export function createAccount(account,pwd,callback){
    ipcRenderer.send('createAccount',account,pwd)
    ipcRenderer.once('createAccount',(event,resp)=>{
        return callback(resp)
    })
}

export function importKeystore(file,password,rename,callback){
    ipcRenderer.send('importKeystore',file,password,rename)
    ipcRenderer.once('importKeystore',(event,resp)=>{
        return callback(resp)
    })
}

export function sendMoney(sendPublic,pwd,recipientPublic,amount,callback){
    ipcRenderer.send('sendMoney',sendPublic,pwd,recipientPublic,amount)
    ipcRenderer.once('sendMoney',(event,resp)=>{
        return callback(resp)
    })
}

export function getBalances(callback){
    ipcRenderer.send('getBalances')
    ipcRenderer.once('getBalances',(event,resp)=>{
        return callback(resp)
    })
}

export function changePassword(publicKey,pwd,newPwd,callback){
    ipcRenderer.send('changePassword',publicKey,pwd,newPwd)
    ipcRenderer.once('changePassword',(event,resp)=>{
        return callback(resp)
    })
}

export function removeWallet(publicKey,pwd,callback){
    ipcRenderer.send('remove-wallet',publicKey,pwd)
    ipcRenderer.once('remove-wallet',(event,resp)=>{
        return callback(resp)
    })
}
// ipcRenderer.send('get-private','adf4c9d1bf8d04bce276a3ceb57f70b820d2d4982d2b83d0143f4123f2dd018c','123456')

export function getPrivate(publicKey,pwd,callback){
    ipcRenderer.send('get-private',publicKey,pwd)
    // ipcRenderer.once('get-private',(event,resp)=>{
    //     return callback(resp)
    // })
}

// ipcRenderer.on('get-error',(event,err)=>{
//     console.log(err)
//     dialog.showMessageBox({type:'error',title: err.title,content:err.msg})
// })

export function showaccount(callback){
    ipcRenderer.send('show-wallet')
    ipcRenderer.once('show-wallet',(event,resp)=>{
        return callback(resp)
    })
}

export function showaccountCallback(callback){
    
}

export function getAccountInfo(key,page,size,callback){
    ipcRenderer.send('get-Account-Info',key,page,size)
    ipcRenderer.once('get-Account-Info',(event,resp)=>{
        return callback(resp)
    })
}

export function exportwallet(publicKey,path,callback){
    ipcRenderer.send('export-wallet',publicKey,path)
    ipcRenderer.once('export-wallet',(event,resp)=>{
        return callback(resp)
    })
}

export function getInitdata(callback){
    // ipcRenderer.send('test','happy come now friend meaning I beautiful together kind air morning love philosophy')
    // testCoin("2ce6f8eccde2e8846a1e270df6ca6db7175469d654c151a3db4354e4e7a49d94",function(resp){
    //     console.log("test",resp)
    // })
    ipcRenderer.send('getInitdata')
    ipcRenderer.once('getInitdata',(event,resp)=>{
        return callback(resp)
    })
}

export function checkUpdate(){
    ipcRenderer.send('check-update')
}

export function updateFinished(callback){
    ipcRenderer.once('updateFinished',(event,resp)=>{
        return callback(resp)
    })
}

export function updateNow(){
    ipcRenderer.send("updateNow")
}

export function version(callback){
    ipcRenderer.send('versions')
    ipcRenderer.once('version',(event,resp)=>{
        return callback(resp)
    })
}
//申请币。
export function testCoin(address,callback){
    ipcRenderer.send("test_coin",address)
    ipcRenderer.once('test_coin',(event,resp)=>{
        return callback(resp)
    })
}
